package com.cmc.cloud.cmclink.doc.controller.admin.si;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.BlnoVslvoyConvert;
import com.cmc.cloud.cmclink.doc.entity.BlnoVslvoyDO;
import com.cmc.cloud.cmclink.doc.service.si.BlnoVslvoyService;
import com.cmc.cloud.cmclink.doc.vo.blnovo.BlnoTransferVO;
import com.cmc.cloud.cmclink.doc.vo.blnovslvoyvo.*;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 提单航线船期信息前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 提单航线船期信息")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "blno-vslvoy")
public class BlnoVslvoyController {

    @Resource
    private BlnoVslvoyService blnoVslvoyService;

    @Operation(summary = "创建提单航线船期信息")
    @OperateLog(type = OperateTypeEnum.CREATE)
    @PostMapping("/create")
    public CommonResult<Void> createBlnoVslvoy(@Valid @RequestBody BlnoVslvoyCreateReqVO createReqVO) {
        blnoVslvoyService.createBlnoVslvoy(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新提单航线船期信息")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @PostMapping("/update")
    public CommonResult<Void> updateBlnoVslvoy(@Valid @RequestBody BlnoVslvoyUpdateReqVO updateReqVO) {
        blnoVslvoyService.updateBlnoVslvoy(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除提单航线船期信息")
    @OperateLog(type = OperateTypeEnum.DELETE)
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteBlnoVslvoy(@PathVariable("id") Long id) {
        blnoVslvoyService.deleteBlnoVslvoy(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得提单航线船期信息")
    @OperateLog(type = OperateTypeEnum.GET)
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BlnoVslvoyRespVO> getBlnoVslvoy(@PathVariable("id") Long id) {
        BlnoVslvoyDO blnoVslvoy = blnoVslvoyService.getBlnoVslvoy(id);
        return CommonResult.success(BlnoVslvoyConvert.INSTANCE.convert(blnoVslvoy));
    }

    @Operation(summary = "获得提单航线船期信息列表")
    @OperateLog(type = OperateTypeEnum.GET)
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<BlnoVslvoyRespVO>> getBlnoVslvoyList(@RequestParam("ids") Collection<Long> ids) {
        List<BlnoVslvoyDO> list = blnoVslvoyService.getBlnoVslvoyList(ids);
        return CommonResult.success(BlnoVslvoyConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得提单航线船期信息分页")
    @OperateLog(type = OperateTypeEnum.GET)
    @GetMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<BlnoVslvoyRespVO>> getBlnoVslvoyPage(@Valid BlnoVslvoyPageReqVO pageVO) {
        PageResult<BlnoVslvoyDO> pageResult = blnoVslvoyService.getBlnoVslvoyPage(pageVO);
        List<BlnoVslvoyRespVO> results = BlnoVslvoyConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }


    @Operation(summary = "获得提单航线船期List信息")
    @OperateLog(type = OperateTypeEnum.GET)
    @GetMapping("/getBlnoVslvoyInfo/{id}")
    @PreAuthorize("@ss.hasPermission('doc:setupTransshipment:voyage')")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<List<BlnoVslvoyRespVO>> getBlnoVslvoyInfo(@PathVariable("id") Long id) {
        List<BlnoVslvoyDO> blnoVslvoy = blnoVslvoyService.getBlnoVslvoyInfo(id);
        return CommonResult.success(BlnoVslvoyConvert.INSTANCE.convertList(blnoVslvoy));
    }

    @Operation(summary = "回显更改数据")
    @OperateLog(type = OperateTypeEnum.GET)
    @PostMapping("/showBlnoVslvoy")
    @PreAuthorize("@ss.hasPermission('doc:setupTransshipment:voyage')")
    public CommonResult<BlnoVslvoyRespVO> showBlnoVslvoy(@Valid @RequestBody BlnoTransferVO reqVO) {
        BlnoVslvoyDO blnoVslvoy = blnoVslvoyService.showBlnoVslvoy(reqVO);
        return CommonResult.success(BlnoVslvoyConvert.INSTANCE.convert(blnoVslvoy));
    }

    @Operation(summary = "中转更新船期航线信息")
    @OperateLog(type = OperateTypeEnum.GET)
    @PostMapping("/updateBlnoVslvoyTrans")
    public CommonResult<Void> updateBlnoVslvoyTrans(@Valid @RequestBody BlnoTransferVO updateReqVO) {
        blnoVslvoyService.updateBlnoVslvoyTrans(updateReqVO);
        return CommonResult.success();
    }
}
